package net.oschina.app.fragment.explore;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.google.zxing.activity.CaptureActivity;

import net.oschina.app.R;
import net.oschina.app.base.BaseFragment;
import net.oschina.app.base.Global;
import net.oschina.app.ui.activity.FriendsRircleActivity;
import net.oschina.app.ui.activity.explore.EventActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static android.app.Activity.RESULT_OK;

/**
 * Created by Shinelon on 2017/1/13.
 * 发现模块
 */

public class ExploreFragment extends BaseFragment {
    @BindView(R.id.ll_friends)
    LinearLayout mLlFriends;
    @BindView(R.id.ll_finduser)
    LinearLayout mLlFinduser;
    @BindView(R.id.ll_event)
    LinearLayout mLlEvent;
    @BindView(R.id.ll_scan)
    LinearLayout mLlScan;
    @BindView(R.id.ll_shake)
    LinearLayout mLlShake;
    public static final int REQUEST_CODE = 0;
    @Override
    public int getLayoutRes() {

        return R.layout.fragment_explorer;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this, mRoot);
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.ll_friends, R.id.ll_finduser, R.id.ll_event, R.id.ll_scan, R.id.ll_shake})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_friends:
                Intent intent = new Intent(getContext(),FriendsRircleActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
            case R.id.ll_finduser:
                break;
            case R.id.ll_event:
                Intent intent1 = new Intent(getContext(),EventActivity.class);
                intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent1);
                break;
            case R.id.ll_scan:
                Intent intent2 = new Intent(getActivity(), CaptureActivity.class);
                intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivityForResult(intent2, REQUEST_CODE);

                break;
            case R.id.ll_shake:
                break;
        }
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) { //RESULT_OK = -1
            Bundle bundle = data.getExtras();
            String scanResult = bundle.getString("result");
            Toast.makeText(Global.mContext, scanResult, Toast.LENGTH_LONG).show();
        }
    }

}
